<?php

include 'def.php';

$json_array = array('status'=>'error','error_id'=>'input','error_description'=>'request data error');

session_start();

if( !isset($_SESSION['id']) )
{/*do nothing*/
  $json_array['error_description']="session id not found";
}
else{
	$conn = mysql_connect(DBSERV, DBUSER, DBPASSWD) or die("Couldn't connect to database");
		
	$db = mysql_select_db(DB) or die("Couldn't connect to database");
		
	$query = "select * from class";

	$result = mysql_query($query) or die('Query_failed: ' . mysql_error());

		/*expect multiple rows one*/
		if( mysql_num_rows($result) == 0 )
		{/*something is wrong*/
			$json_array = array('status'=>'error', 'error_id'=>'$id','error_description'=>'data no found');
		}
		else{
			$json_array = array();
			$json_array["status"]="OK";
			$json_array ["data"] = array();
			while($row = mysql_fetch_assoc($result))
			{
				//echo $row;
				$json_array["data"][] = $row;
			}
	}
}		

echo json_encode($json_array);

?>